<html>
<head><meta charset="utf-8"><title>in scope trait implementations for type · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/in.20scope.20trait.20implementations.20for.20type.html">in scope trait implementations for type</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198051389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/in%20scope%20trait%20implementations%20for%20type/near/198051389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jakob Beckmann <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/in.20scope.20trait.20implementations.20for.20type.html#198051389">(May 19 2020 at 11:25)</a>:</h4>
<p>Hi, I am working on a compiler plugin and need to find the trait <em>declarations</em> for all traits implemented on a type that are in scope. More specifically, for some method declaration taking a parameter of type <code>Type</code> that implements <code>Trait1</code> and <code>Trait2</code>, I would like to get a reference (<code>DefId</code>) to the <em>declaration</em> of <code>Trait1</code> considering it is the only one of the two in scope (at the definition point of the method).</p>
<p>I looked through <code>TyCtxt</code> and found ways to get traits in scope, trait declarations from some implementation, but no way to get implementations/declarations for some type. The only reliable way I stumbled upon is via defined methods on the type using <code>impl_of_method</code>. The issue is that I need to work mostly with marker traits which don't declare any methods.</p>
<p>Does anyone here know what methods/documentation I should look at to achieve this? Cheers!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>